package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfKeyword;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfKeywordService;
import com.yuandian.management.vo.BusinessServerResourceParams;
import com.yuandian.management.vo.SegmentRelationByCodeVo;
import com.yuandian.management.vo.SysBusiRelationByCodeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 识别关键字表-Controller
 * @author zfsn
 * @date 2023-3-27
 */
@Api(tags = "专属指标详情配置-识别关键字列表")
@RestController
@RequestMapping("/keyword")
public class ConfKeywordController {

	@Autowired
	private ConfKeywordService confKeywordService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfKeyword>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confKeywordService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confKeyword 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "source", value = "来源", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "matchStr", value = "匹配串", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "keyword", value = "关键字", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "resourceCode", value = "服务资源编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "stepCode", value = "步骤编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "businessCode", value = "步骤编码", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "systemId", value = "系统id", paramType = "body", required = false, dataType = "Integer"),
				})
	public R<Page<ConfKeyword>> listPage(@RequestBody ConfKeyword confKeyword) {
		return R.ok(confKeywordService.listPage(confKeyword));
	}

	/**
	 * 新增数据
	 * @param confKeyword 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增识别关键字表数据")
	@PostMapping("/save")
	public R<String> saveKeyWord(@RequestBody ConfKeyword confKeyword) {
		return confKeywordService.saveKeyWord(confKeyword);
	}

	/**
	 * 通过主键更新数据
	 * @param confKeyword 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新识别关键字表数据")
	@PutMapping
	public R<String> updateById(@RequestBody ConfKeyword confKeyword) {
		return confKeywordService.updateKeyWordById(confKeyword);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除识别关键字表数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> ids){
		return R.ok(confKeywordService.removeByIds(ids));
	}


	/**
	 * 通过业务服务资源编码查询系统业务关联关系列表
	 * @param serverResourceParams 业务服务资源接口请求对象
	 * @return 通用返回对象
	 */
	@GetMapping("/querySysBusiRelationByResourceCode")
	@ApiOperation(value = "通过业务服务资源编码查询系统业务关联关系列表", notes = "通过业务服务资源编码查询系统业务关联关系列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", value = "服务资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
	})
	public R<Page<SysBusiRelationByCodeVo>> querySysBusiRelationByResourceCode(BusinessServerResourceParams serverResourceParams) {
		Page<SysBusiRelationByCodeVo> pageDataInfo = confKeywordService.querySysBusiRelationByResourceCode(serverResourceParams);
		return R.ok(pageDataInfo);
	}


	/**
	 * 通过业务服务资源编码查询网端关联关系列表
	 * @param params 业务服务资源接口请求对象
	 * @return 通用返回对象
	 */
	@GetMapping("/querySegmentRelationByResourceCode")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", value = "服务资源编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataTypeClass = Integer.class),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataTypeClass = Integer.class),
	})
	public R querySegmentRelationByResourceCode(BusinessServerResourceParams params) {
		if (params.getPageNum() == null || params.getPageSize() == null){
			params.setPageNum(1);
			params.setPageSize(10);
		}
		Page<SegmentRelationByCodeVo> page = confKeywordService.querySegmentRelationByResourceCode(params);
		return R.ok(page);
	}

}